<template>
  <div id="qrcode">  
   
   <div  style="display:flex;align-items: center;">
          <img class="top_img" src="@/assets/images/a8.png" style="width:35px;height:35px;margin-right:10px;"/>
          <div style="line-height: 40px;font-weight:bold:">客服管理</div>
    </div> 

    <el-form ref="form"  label-width="0px">  
     <el-row> 
             <el-col :span="24" style="text-align: right;">   
                <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;" @click="add_but()">
                  <img class="custom_color_button1_img" src="@/assets/images/but_bg2.png" />添加
                </el-button>         
             </el-col>  
    </el-row>
   </el-form>

   <!-- 渲染数据list -->
   <qr-code-list :detaildata="detaildata" @up_list_fun="list_fun"> </qr-code-list>

      
   <div style="margin-top:20px;text-align: center;">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :page-size="10"  
        layout="prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>

       <!-- 添加二维码 -->
    <el-dialog title="添加二维码" :visible.sync="add_mtk"  width="500px" :close-on-click-modal="false">
        <div style="width:100%;"> 


        <el-form ref="form"   label-width="70px" style="width:100%;">

            <el-form-item label="名称">
                        <el-input  v-model="mtk_form.title" placeholder="名称"></el-input>
            </el-form-item> 

             <el-form-item label="手机号">
                        <el-input  v-model="mtk_form.phone" placeholder="名称"></el-input>
            </el-form-item>  

             <el-form-item label="匹配次数">
                        <el-input  v-model="mtk_form.get_count" placeholder="名称"></el-input>
            </el-form-item>        
                              

              <el-row>
                <el-col :span="12">
                    <el-form-item label="二维码">
                            <el-upload 
                                    action="uploadUrl"  
                                    :show-file-list="false"   
                                    :before-upload="beforeupload_qrcode_pic"
                                    :http-request="ImgUploadSectionFile">
                                    <div class="avatar-uploader">
                                        <img v-if="pic_form_qrcode.head_img"  :src="pic_form_qrcode.head_img" class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </div>
                            </el-upload>
                    </el-form-item> 
                </el-col>
                <el-col :span="12">
                     <el-form-item label="头像">
                            <el-upload 
                                    action="uploadUrl"  
                                    :show-file-list="false"   
                                    :before-upload="beforeupload_tx_pic"
                                    :http-request="ImgUploadSectionFile">
                                    <div class="avatar-uploader">
                                        <img v-if="pic_form_tx.head_img"  :src="pic_form_tx.head_img" class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </div>
                            </el-upload>
                    </el-form-item> 
                </el-col>
            </el-row>

           


        </el-form>
  
            
        <div style="text-align: center;width:50%;margin:auto;">
            <el-button type="primary" class="custom_color_button" style="width:80%;" @click="add_qr_but()">确认</el-button>
        </div>

        </div>
    </el-dialog>

      
  </div>
</template>

<script>
import QrCodeList from '@/view/Aftersale/QrCodeList'
export default {
  name: 'qrcode',
  data () {
    return {
        detaildata:[],
        page:1,
        count:0,
        add_mtk:false,
        mtk_form:{
            title:'',
            phone:'',
            get_count:''
        },
        pic_form_qrcode:{ //二维码缩略图
            head_img:'',
            upfile:'',
       },
       pic_form_tx:{  //头像
           head_img:'',
            upfile:'',
       }
    }
  },
 components:{
    QrCodeList
  },
  created(){
       this.list_fun()
  },
  mounted (){
    
  },
  methods: {
     list_fun(){
        this.post("/customer_service/listOfData", {
            page:this.page
        }).then(res => {  
            this.count = res.result.count
            this.detaildata = res.result.list
            console.log( this.detaildata)
            for(let item of this.detaildata) {
               
                item.qr_code_picture = [this.urlimg + item.qr_code]

                
                          
             }
        })
     },
     add_but(){
         this.mtk_form={
            title:'',
            phone:'',
            get_count:''
        }
         this.add_mtk = true
         this.pic_form_qrcode={ //二维码缩略图
            head_img:'',
            upfile:'',
         }
         this.pic_form_tx={  //头像
            head_img:'',
            upfile:'',
         }
     },
     add_qr_but(){
        this.post("/customer_service/create", {
                name:this.mtk_form.title,
                get_count:this.mtk_form.get_count,
                telphone:this.mtk_form.phone,
                qr_code:this.pic_form_qrcode.upfile,
                head_img:this.pic_form_tx.upfile,
              }).then(res => {
                if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.add_mtk = false
                    this.list_fun()
                }else {
                    this.open1(res.message,'warning')
                }

            })
     },
      ImgUploadSectionFile(param){//图片上传    
      },
      beforeupload_qrcode_pic(file){  //商户封面
        if(this.upimglx(file) == false){  //判断是否为fales
              this.upimglxtitle()  //执行弹出错误             
              return false
            }  
            var windowURL = window.URL || window.webkitURL;               
            this.pic_form_qrcode.head_img=windowURL.createObjectURL(file);                
            
             this.upimgpost("/image/uploadMultiple",file).then(res => {
               console.log(res.result.url,"二维码")
               this.pic_form_qrcode.upfile = res.result.url    
            })

            return false;
     },
     beforeupload_tx_pic(file){
          if(this.upimglx(file) == false){  //判断是否为fales
              this.upimglxtitle()  //执行弹出错误             
              return false
            }  
            var windowURL = window.URL || window.webkitURL;               
            this.pic_form_tx.head_img=windowURL.createObjectURL(file);                
            
             this.upimgpost("/image/uploadMultiple",file).then(res => {
               console.log(res.result.url,"头像")
               this.pic_form_tx.upfile = res.result.url    
            })

            return false;
     },
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val
        this.list_fun()
        console.log(`当前页: ${val}`);
      }
  }
}
</script>


<style scoped>
.avatar-uploader  {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 150px;
    height: 150px;
    line-height: 150px;
    text-align: center;
  }
  .avatar {
    width: 150px;
    height: 150px;
    display: block;
  }

</style>
